Skip to content

Add vendor_id and finish_reason to Gemini/Google model responses #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 27, 2025

Conversation

davide-andreoli
Copy link
Contributor

@davide-andreoli davide-andreoli commented May 21, 2025

Add id and finish_reason to Gemini

Description

Following PR#1761 , this update adds vendor_id and finish_reason to Gemini answers.

Below the details:

  • vendor_id: maps to responseId
  • finish_reason: finishReason for the first candidate of the output. The finish reason is added in vendor_details, following the attribute specification

The handling of finish_reasons aligns with the current approach for other response parts, where only the first candidate's reason is considered.

Testing

The changes were validated using my API key, and the behavior matches expectations.

Impact

This update impacts only Gemini Responses, but it is not a breaking change.

@davide-andreoli
Copy link
Contributor Author

Hello @DouweM, as agreed in PR#1761, here is the new PR.

@DouweM DouweM closed this May 21, 2025
@DouweM DouweM reopened this May 21, 2025
@DouweM
Copy link
Contributor

DouweM commented May 21, 2025

@davide-andreoli Thanks! Can you please have a look at the failing tests, and also implement this in the new models/google.py (assuming it makes sense there as well)?

@davide-andreoli
Copy link
Contributor Author

@DouweM The test failures are due to the vendor_details field.
Since gemini tests are configured to always send a finish_reason (which makes sense, as it's a non-optional field in the response) the vendor_details field is awlays present in the Gemini ModelResponses.
However, the snapshot comparison fails because vendor_details is marked with repr=False in the ModelResponse class.

I see two potential ways to address this:

  1. Remove repr=False from the vendor_details field in the ModelResponse class. This would be the cleanest solution, but I want to make sure it doesn't go against the original design intent
  2. Update the tests to exclude vendor_details before performing snapshot comparisons. This is a bit less elegant but still effective

Please let me know which approach you’d prefer.

And sure, no problem with adding the fields to models/google.py as well.

@DouweM
Copy link
Contributor

DouweM commented May 22, 2025

@davide-andreoli I had a chat about this with @dmontagu and we decided to make it so that dataclass fields with default values are excluded from reps: #1812. So once that merges (should be soon), you can merge/rebase, drop reps=False from vendor_details and hopefully it won't require too many examples to be updated!

@davide-andreoli davide-andreoli force-pushed the feat/add-id-to-gemini branch from 28dec6a to 273e783 Compare May 23, 2025 07:12
@davide-andreoli
Copy link
Contributor Author

Hello @DouweM, work is done and tests are passing.
As agreed I removed repr=False from vendor_details and added the fields in models/google.py as well.

@DouweM DouweM changed the title Add id and finish_reason to Gemini Add vendor_id and finish_reason to Gemini/Google model responses May 27, 2025
@DouweM DouweM merged commit 1e22652 into pydantic:main May 27, 2025
18 checks passed
@DouweM
Copy link
Contributor

DouweM commented May 27, 2025

@davide-andreoli Thanks Davide!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants